package com.houweishi.module.region.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.module.region.domain.BizRegion;
import com.houweishi.module.region.service.IBizRegionService;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.common.core.page.TableDataInfo;

/**
 * 自助入网-地区Controller
 * 
 * @author houweishi
 * @date 2023-02-28
 */
@RestController
@RequestMapping("/module/region")
public class BizRegionController extends BaseController
{
    @Autowired
    private IBizRegionService bizRegionService;

    /**
     * 查询自助入网-地区列表
     */
    @PreAuthorize("@ss.hasPermi('module:region:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizRegion bizRegion)
    {
        startPage();
        List<BizRegion> list = bizRegionService.selectBizRegionList(bizRegion);
        return getDataTable(list);
    }

    /**
     * 导出自助入网-地区列表
     */
    @PreAuthorize("@ss.hasPermi('module:region:export')")
    @Log(title = "自助入网-地区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizRegion bizRegion)
    {
        List<BizRegion> list = bizRegionService.selectBizRegionList(bizRegion);
        ExcelUtil<BizRegion> util = new ExcelUtil<BizRegion>(BizRegion.class);
        util.exportExcel(response, list, "自助入网-地区数据");
    }

    /**
     * 获取自助入网-地区详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:region:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizRegionService.selectBizRegionById(id));
    }

    /**
     * 新增自助入网-地区
     */
    @PreAuthorize("@ss.hasPermi('module:region:add')")
    @Log(title = "自助入网-地区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizRegion bizRegion)
    {
        return toAjax(bizRegionService.insertBizRegion(bizRegion));
    }

    /**
     * 修改自助入网-地区
     */
    @PreAuthorize("@ss.hasPermi('module:region:edit')")
    @Log(title = "自助入网-地区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizRegion bizRegion)
    {
        return toAjax(bizRegionService.updateBizRegion(bizRegion));
    }

    /**
     * 删除自助入网-地区
     */
    @PreAuthorize("@ss.hasPermi('module:region:remove')")
    @Log(title = "自助入网-地区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizRegionService.deleteBizRegionByIds(ids));
    }

    /**
     * 获取地区列表
     */
    @PostMapping("/regionList")
    public TableDataInfo regionList(BizRegion region) {
        List<Map<String, Object>>  arrayProvinceList = bizRegionService.selectTreeList();
        return getDataTable(arrayProvinceList);
    }
}
